//
//  CXHUnStandardViewController.m
//  CXHAdSDK_Example
//
//  Created by 陈坤 on 2022/5/30.
//  Copyright © 2022 陈桑葚吃桑葚. All rights reserved.
//

#import "CXHUnStandardViewController.h"
#import <CXHAdSDK-Core/CXHAdSDK.h>
#import <CXHAdSDK-Core/CXHAdSDKBannerAdView.h>
#import <CXHAdSDK-Kit/CXHUtilsKit.h>
#import <CXHAdSDK-Adapter/CXHAdSDKAdapter.h>

@interface CXHUnStandardViewController ()<CXHSDKBannerAdViewDelegate>{
    CXHAdSDKBannerAdView *_bannerView;
}

@end

@implementation CXHUnStandardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    UIBarButtonItem *itemLeft = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(onCancelClicked:)];
    self.navigationItem.leftBarButtonItem = itemLeft;
    
    UIButton *btn2 = [UIButton new];
    btn2.backgroundColor = [UIColor orangeColor];
    btn2.layer.cornerRadius = 20;
    
    btn2.frame = CGRectMake((kCXHScreenWidth -200)/2, kCXHTopBarHeight + 100, 200, 40);
    [btn2 setTitle:@"load unstandarAd" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:btn2];
    [btn2 addTarget:self action:@selector(loadad) forControlEvents:UIControlEventTouchUpInside];
    
    
}

- (void)onCancelClicked:(id)sender {
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}

- (void)loadad{
    CGFloat height = [UIScreen mainScreen].bounds.size.width * 110/335;
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    
    // 1 初始化非标准广告
    _bannerView = [[CXHAdSDKBannerAdView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
    _bannerView.delegate = self;
    _bannerView.controller = self;
    _bannerView.refershTime = 35;
//    _bannerView.posId = @"MSX_KP_00001";
    _bannerView.posId = @"MSX_BN_00003";
    _bannerView.backgroundColor = [UIColor whiteColor];
    
    // 2 添加到父视图上
    _bannerView.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height  - height - 100, width, height);
    [self.view addSubview:_bannerView];
    [_bannerView loadAndShow];
}

/**
 广告获取成功
 
 @param bannerView banner实例
 */
- (void)CXH_bannerViewDidReceived:(CXHAdSDKBannerAdView *)bannerView {
    
}

/**
 广告拉取失败
 
 @param bannerView banner实例
 @param error 错误描述
 */
- (void)CXH_bannerViewFailToReceived:(CXHAdSDKBannerAdView *)bannerView error:(NSError *)error{
    
}

/**
 广告点击
 
 @param bannerView 广告实例
 @param loadingPageURL 广告落地页地址，当渠道为bwt，并且customLoadingPage为YES时有值
 */
- (void)CXH_bannerViewClicked:(CXHAdSDKBannerAdView *)bannerView loadingPageURL:(NSString *)loadingPageURL{
    
}

/**
 广告关闭
 
 @param bannerView 广告实例
 */
- (void)CXH_bannerViewClose:(CXHAdSDKBannerAdView *)bannerView{
    
}

/**
 广告展示
 
 @param bannerView 广告实例
 */
- (void)CXH_bannerViewExposure:(CXHAdSDKBannerAdView *)bannerView{
    
}

/**
 关闭落地页
 
 @param bannerView 广告实例
 */
- (void)CXH_bannerAdCloseLandingPage:(CXHAdSDKBannerAdView *)bannerView{
    
}

@end
